﻿using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Collections.ObjectModel;
using WS_Manager_ShopMob.ViewModels;
using System.Net;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Json;
using Newtonsoft.Json;
using WS_Manager_ShopMob.Model;
using System.Runtime.Serialization;

namespace WS_Manager_ShopMob.ViewModels
{
    [DataContract]
    public class MainViewModel : BaseViewModel
    {
        //private Model.Repository repo = new Model.Repository();
        private IRepository repo = Data.GetModel;
        
        public MainViewModel()
        {
        }

        private ObservableCollection<ViewModels.CommandeViewModel> listCommandes = new ObservableCollection<ViewModels.CommandeViewModel>();

        public ObservableCollection<ViewModels.CommandeViewModel> ListCommandes
        {
            get { return listCommandes; }
            set { listCommandes = value; }
        }

        public void LoadData(long id)
        {
            repo.GetCommandesParLivreur(id, delegate(string resu, Exception e)
            {
                var des = JsonConvert.DeserializeObject<List<DBO_ShopMob.Commande>>(resu);
                foreach (var commande in des)
                {
                    ListCommandes.Add(new CommandeViewModel() { RefCommande = commande.RefCommande, DateCommande = commande.DateCommande, DateLivraison = commande.DateLivraison, Statut = commande.Statut, Client = commande.Client, Magasin = commande.Magasin });
                }
            });
        }
    }
}